/**
 * Created by DuHuiling on 2017/4/24.
 */
var HyperLink = require('../../../../src/libs/hyperlink');
var Label = require('../../../../src/libs/label');
var FormItem = require('../../../../src/libs/form-item');
var Input = require('../../../../src/libs/input');
var Password = require('../../../../src/libs/password');
var SelectDropDown = require('../../../../src/libs/select-drop-down');
var Button = require('../../../../src/libs/button');
var Checkbox = require('../../../../src/libs/checkbox');

var BackAccount = React.createClass({
    getInitialState:function(){
        return {
            PayBankCards: this.props.PayBankCards,
            userInfo: this.props.userInfo,
            url: this.props.url,
            checkbox:this.props.checkbox
        }
    },
    _change: function (v) {    //修改银行卡id
        PageDM.PayBankCards.value.BankCardId = v.value;
    },
    componentDidMount:function(){
        var _this = this;
        //回款账户
        UEventHub.on(PageDM.PayBankCards.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function (v) {
            _this.setState({
                PayBankCards:v
            });
        });
        //身份信息
        UEventHub.on(PageDM.userInfo.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function (v) {
            _this.setState({
                userInfo:v
            });
        });
    },
    render:function(){
        var _this = this;

        var options = [],BList = _this.state.PayBankCards;
        for (var i=0; i< BList.BankAccountList.length;i++) {
            var item = BList.BankAccountList[i];
            options.push({
                option: "<div><span class='bank-logo " + item.BankIconCss + "'></span><b>" + item.AccountNoShortHide + "</b></div>",
                value: item.BankCode
            });
        }
        var defaultValue = BList.SelectIndex - 1;

        PageDM.PayBankCards.value.BankCardId = BList.BankAccountList[defaultValue].BankCode;    //初始银行卡id

        return(
            <div>
                {this.state.PayBankCards.Status == 1 ?
                    <div>
                        <div className="title"><b></b>身份信息<b></b></div>
                        <div className="confirm-id fc-dark">
                            {this.state.userInfo.realName !== undefined && this.state.userInfo.realName !== null ?
                                <p>真实姓名：{this.state.userInfo.realName}</p> : ""
                            }
                            {this.state.userInfo.IDcard !== undefined && this.state.userInfo.IDcard !== null ?
                                <p>身份证号码：{this.state.userInfo.IDcard}</p> : ""
                            }
                        </div>
                    </div> : ""
                }

                <div className="title">
                    <b></b>回款账户<b></b>
                    <span className="fc-main tips"><i className="iconfont icon-tips"></i>（温馨提示：您所选择的银行账户将用于支付投标款项和收取投标本金及收益）</span>
                </div>

                {
                    this.state.PayBankCards.Status == 1 ?
                        <div>
                            <div className="confirm-bank-con clearfix fc-dark">
                                <span className="f-left">银行账户：</span>
                                <div className="f-left">
                                    <div className="form-group" ref="test">
                                        <SelectDropDown options={options} defaultValue={defaultValue}
                                                        onChange={_this._change.bind(this)}/>
                                    </div>
                                </div>
                                <HyperLink className="bank-add" text='<span><i className="iconfont icon-add"></i>添加账户</span>'
                                           href={this.props.url.addCard}/>
                            </div>
                            <div className="confirm-bank-con fc-dark" style={{paddingLeft:"0"}}>
                                <Label value="手机号："/>{this.state.PayBankCards.StayMobile} <span className="fc-light">（此号码用于接收您的投资提醒短信）</span>
                            </div>
                            {this.state.PayBankCards.PrjectType == 1 ?
                                <FormItem label="专属码：" dmbind={PageDM.ExclusiveNum.dmbind}>
                                    <Input placeholder="请输入项目专属识别码" dmbind={PageDM.ExclusiveNum.dmbind}/>
                                </FormItem> : ""
                            }
                            <FormItem label="支付密码:" dmbind={PageDM.BussinessPwd.dmbind}>
                                <Password placeholder="请输入支付密码" dmbind={PageDM.BussinessPwd.dmbind}/>
                            </FormItem>
                            <FormItem label="推荐码：" dmbind={PageDM.ReFree.dmbind}>
                                <Input placeholder="请输入推荐码" dmbind={PageDM.ReFree.dmbind}/>
                            </FormItem>
                        </div> :
                    this.state.PayBankCards.Status == 2 ?
                        <div className="confirm-bank-con clearfix fc-dark">
                            <span className="f-left">您还没有绑定银行卡，赶紧</span>
                            <HyperLink className="bank-add" text='<span><i className="iconfont icon-add"></i>添加账户</span>'
                                       href={this.props.url.addCard}/>
                        </div> : ""
                }

                <div className="confirm-agree">
                    <div className="check">
                        <Checkbox text=" 我同意" checked={this.state.checkbox.checked} onclick={this.state.checkbox.onClick}/>
                        <a className="fc-link" href={this.props.url.agreement}>《绵阳市商业银行平台服务协议（个人版）》</a>
                    </div>
                    <div className="fc-light tip">
                        <p><span>*</span> <b>温馨提示</b>回款账户作为所有投资本金和收益的接收账户，仅限储蓄卡。</p>
                        <p><span>*</span> <b>免责声明</b>预期收益率仅供参考，具体以实际发生收益为准。
                        </p>
                    </div>
                </div>
                <div className="confirm-btn">
                    <Button value="确定购买" className="ucs-btn-confirm btn-block" onclick={PageDM.btn.onClick}/>
                </div>
            </div>

        )
    }
});
module.exports = BackAccount;